package ru.jexp.rcp.supply.beans.account;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import ru.jexp.izdelie.zaavkatrebovanie.ZaavkaTrebovanieLite;
import ru.jexp.rcp.supply.beans.zt.Requirment;
import ru.jexp.rcp.supply.mui.JExpSupplyMessages;
import ru.jexp.rcp.supply.swtext.JExpChangeElementEvent;
import ru.jexp.rcp.supply.swtext.JExpChangeElementListener;
import ru.jexp.rcp.supply.swtext.JExpControlLookup;
import ru.jexp.rcp.supply.swtext.factory.JExpLookupFactory;

public class WizardPageRequirment extends WizardPage implements
		JExpChangeElementListener {

	private JExpControlLookup requirment;

	protected WizardPageRequirment() {
		super(JExpSupplyMessages.Account_wizard_reqiurment_pagename);
		setTitle(JExpSupplyMessages.Account_wizard_reqiurment_pagename);
	}

	@Override
	public void createControl(Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));
		requirment = JExpLookupFactory.createRequirmentLookup(composite, 200);
		requirment.addChangeElementListener(this);

		setControl(composite);
		
		setPageComplete(false);
	}

	public ZaavkaTrebovanieLite getRequirment() {
		Requirment selected = (Requirment) requirment.getSelectedElement();
		return selected.getLiteBean();
	}

	@Override
	public void change(JExpChangeElementEvent event) {
		getWizardAccount().fireWizardListeners(
				NewWizardAccountPresentor.CHANGE_REQUIRMENT);
	}

	private NewWizardAccount getWizardAccount() {
		return (NewWizardAccount) getWizard();
	}
}
